package com.ssy.bus.controller;

import com.ssy.bus.pojo.CaseOrder;
import com.ssy.bus.service.ICaseOrderService;
import com.ssy.bus.vo.CaseOrderVo;
import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ssy
 */
@RestController
@RequestMapping("/caseOrder")
public class CaseOrderController {

    @Autowired
    private ICaseOrderService caseOrderService;

    /**
     * 生成缴费订单
     *
     * @param caseOrder caseOrder
     * @return data
     */
    @PostMapping("/addCaseOrder")
    public Result addCaseOrder(CaseOrder caseOrder) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        caseOrder.setOrderId("OD" + sdf.format(new Date()).substring(2));
        caseOrder.setCreateTime(new Date());
        caseOrder.setOrderState(1);
        return this.caseOrderService.insertCaseOrder(caseOrder);
    }

    /**
     * 加载收费查询列表
     *
     * @param caseOrderVo 查询数据
     * @return data
     */
    @GetMapping("/loadCaseOrderPage")
    public PageResult loadCaseOrderPage(CaseOrderVo caseOrderVo) {
        return this.caseOrderService.selectCaseOrderByPage(caseOrderVo);
    }

    /**
     * 药品出库
     *
     * @param outpatientId 挂号单ID
     * @return result
     */
    @GetMapping("/grantDrug/{outpatientId}")
    public Result grantDrug(@PathVariable String outpatientId) {
        return this.caseOrderService.grantDrug(outpatientId);
    }

}
